from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from datetime import datetime
from ..database import Base

class Template(Base):
    __tablename__ = "templates"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), nullable=False, index=True)
    description = Column(Text)
    content = Column(Text, nullable=False)  # 模板内容/大纲
    template_type = Column(String(50), default="outline")  # outline, document等
    format_type = Column(String(20), default="markdown")  # markdown, html, docx等
    
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    
    # 外键
    creator_id = Column(Integer, ForeignKey("users.id"))
    
    # 关系
    creator = relationship("User", back_populates="templates") 